home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / TUTORC.ZIP / TUT12.C < prev    next >
C/C++ Source or Header  |  1994-10-30  |  6KB  |  177 lines

  1. /* 
  2.   tut12.c
  3.   10/30/94
  4.   from tutprog12.pas
  5.   Adapted from Denthor's tutprog12.pas
  6.   Translated into C, from Denthor's VGA Trainer, by
  7.   Steve Pinault, scp@ohm.att.com
  8.   Compiled with Microsoft Visual C++ 1.5 (Microsoft C 8.0)
  9.   To compile:
  10.   First compile the subroutines in tutsubs.c with the batch file 
  11.   cltutsub.bat
  12.   Then compile any of the tutor programs with the batch file
  13.   cltut.bat
  14.   Example: C:>cltutsub
  15.            C:>cltut tut12.c
  16.            to compile this program.
  17. */
  18.  
  19. #include "tutheadr.h"
  20. #define SIZE 80
  21.                        //    { Size =  40 = 1 across, 4 down }
  22.                        //    { Size =  80 = 2 across, 2 down }
  23.                        //    { Size = 160 = 4 across, 1 down }
  24. char terrain[21][256];
  25. // base 8 are desert, top 13 are letters }
  26. char far* des = &terrain[0][0];
  27.  
  28.  
  29.  
  30. // {DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD}
  31. // procedure LoadPal (FileName : string);
  32. //  { This loads .col file and sets the pallette }
  33. void LoadPal(char* FileName)
  34. {
  35.   FILE* fptr;
  36.   char dac[256][3];
  37.   char far* dacptr=&dac[0][0];
  38.   
  39.   if((fptr=fopen(FileName,"rb"))==NULL)
  40.   {
  41.     SetText();
  42.     printf("Error opening file %s\n",FileName);
  43.     exit(1);
  44.   }
  45.   fread(dac,sizeof(char),768,fptr);
  46.   fclose(fptr);                    
  47.   SetAllPal(dacptr);
  48. }  
  49.  
  50.  
  51. // {DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD}
  52. // Procedure Init;
  53. //  { We get our memory and load the graphics here }
  54. void Init()
  55. {
  56.   FILE* fptr;
  57.   if((fptr=fopen("piccs.dat","rb"))==NULL)
  58.   {
  59.     SetText();
  60.     printf("Error opening file piccs.dat\n");
  61.     exit(1);
  62.   }
  63.   fread(des,sizeof(char),21*256,fptr);
  64.   fclose(fptr);                    
  65.   LoadPal ("pallette.col");
  66. }
  67.  
  68.  
  69. // {DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD}
  70. // Procedure Play;
  71. //  { Our main procedure }
  72. void Play()
  73. {
  74.   char sAsp[20]=
  75.   {1,3,2,4,5,3,9,10,11,12,13,14,15,9,7,4,5,2,1,4}; //  { Data for 'ASPHYXIA' }
  76. // D D D D D D A S  P  H  Y  X  I  A D D D D D D
  77. // (D = Desert Icon)
  78.   char sVGA[20]=      
  79.   {4,7,1,2,4,5,8,3,16,17,9,5,6,2,5,8,6,2,5,7};     //  { Data for 'VGA' }
  80. //                 V  G  A
  81.   char sTra[20]=      
  82.   {2,5,8,2,1,6,18,19,9,15,20,21,19,7,2,4,1,8,3,4}; //  { Data for 'TRAINER' }
  83. //             T   R A I  N  E  R
  84.   int loop1,loop2;
  85.   int depth,farin;
  86.   char what[20];
  87.   int count;              
  88.    moveto(0,200,SIZE); //{ This moves the view to the left hand corner }
  89.    depth=200;    //{ This is our y for our viewport }
  90.    farin=15;     //{ This is how far in to the icon we have drawn }
  91.    count=0;      //{ This is for when the write ASPHYXIA VGA TRAINER }
  92.  
  93.    for(loop1=0;loop1<20;loop1++)what[loop1]=random(8);
  94.         //{ This sets a random row of desert icons }
  95.    while(1)
  96.    {        
  97.      for(loop1=0;loop1<20;loop1++)
  98.        for(loop2=0;loop2<16;loop2++)
  99.        {
  100.          C4PutPixel (loop1*16+loop2,depth,terrain[what[loop1]][farin*16+loop2],SIZE);
  101.          C4PutPixel (loop1*16+loop2,depth+201,terrain[what[loop1]][farin*16+loop2],SIZE);
  102.        }
  103.        // { This draws the two rows of pixels, above and below the viewport }
  104.      depth--; //{ This moves our viewport up one pixel }
  105.      farin--; //{ This moves us to the next row in our icons }
  106.      if(depth==-1)depth=200; //{We have hit the top, jump to the bottom }
  107.      if(farin==-1)           //{ We have finished our row of icons }
  108.      {
  109.        farin=15;
  110.        for(loop1=0;loop1<20;loop1++)what[loop1]=random(8);
  111.          //{ This sets a random row of desert icons }
  112.        count++;
  113.        if(count==24)for(loop1=0;loop1<20;loop1++)what[loop1]=sAsp[loop1]-1;
  114.        if(count==22)for(loop1=0;loop1<20;loop1++)what[loop1]=sVGA[loop1]-1;
  115.        if(count==20)for(loop1=0;loop1<20;loop1++)what[loop1]=sTra[loop1]-1;
  116.        if(count==50)count=0;
  117.      }
  118.      WaitRetrace();
  119.      moveto(0,depth,SIZE);
  120.      if(_bios_keybrd(_KEYBRD_READY))break;
  121.    }
  122.    getch();
  123. }   
  124.  
  125. void main()
  126. {
  127.   _clearscreen(_GCLEARSCREEN);
  128.   InitChain4(SIZE);
  129.   Init();
  130.   Play();
  131.   SetText();
  132. }  
  133. /*  
  134.   Writeln ('Hello! After a long absence, here is the latest installment of the');
  135.   Writeln ('ASPHYXIA VGA Trainer! This one, by popular demand, is on full screen');
  136.   WRiteln ('scrolling in Chain-4. This isn''t very interactive, just hit any key');
  137.   Writeln ('and a random landscape will scroll by for infinity, with the letters');
  138.   Writeln ('ASPHYXIA VGA TRAINER scrolling passed at set intervals. You will notice');
  139.   Writeln ('that two of our four pages are untouched. These could be put to good');
  140.   Writeln ('use in for example a game etc.');
  141.   Writeln;
  142.   Writeln ('This code could easily be altered to produce a movie-credits type');
  143.   Writeln ('sequence, a large game-map and so on. Have fun with it and see what');
  144.   Writeln ('you can come up with! All desert art is done by Pieter Buys (Fubar), may');
  145.   Writeln ('I add on very short notice by my request. The font was, I think, ripped,');
  146.   Writeln ('I found it lying about on my hard drive.');
  147.   Writeln;
  148.   Writeln ('The code is very easy to follow and you should have it doing what you want');
  149.   Writeln ('in no time.');
  150.   writeln;
  151.   writeln;
  152.   Write ('  Hit any key to contine ...');
  153.   Readkey;
  154.   initChain4;
  155.   init;
  156.   play;
  157.   Freemem (des,sizeof (des^));
  158.   SetText;
  159.   Writeln ('All done. This concludes the twelfth sample program in the ASPHYXIA');
  160.   Writeln ('Training series. You may reach DENTHOR under the names of GRANT');
  161.   Writeln ('SMITH/DENTHOR/ASPHYXIA on the ASPHYXIA BBS. I am also an avid');
  162.   Writeln ('Connectix BBS user, and occasionally read RSAProg. E-mail me at :');
  163.   Writeln ('    smith9@batis.bis.und.ac.za');
  164.   Writeln ('The numbers are available in the main text. You may also write to me at:');
  165.   Writeln ('             Grant Smith');
  166.   Writeln ('             P.O. Box 270');
  167.   Writeln ('             Kloof');
  168.   Writeln ('             3640');
  169.   Writeln ('             Natal');
  170.   Writeln ('             South Africa');
  171.   Writeln ('I hope to hear from you soon!');
  172.   Writeln; Writeln;
  173.   Write   ('Hit any key to exit ...');
  174.   Readkey;
  175. END.
  176. */
  177.